package com.swt.gap.controller;

import com.swt.gap.model.entity.CustomStyle;
import com.swt.gap.service.CustomStyleService;
import io.swagger.annotations.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 请填写说明
 *
 * @author sx
 * @date 2019/9/18 15:50
 */
@Api(tags = "样式，条件格式化")
@RestController
@RequestMapping("/custom-style")
public class CustomStyleController {
    private final CustomStyleService customStyleService;

    public CustomStyleController(CustomStyleService customStyleService) {
        this.customStyleService = customStyleService;
    }

    @PostMapping
    @ApiOperation(notes = "添加格式化方案", value = "添加格式化方案")
    @ApiImplicitParam(paramType = "body", dataType = "CustomStyle", name = "customStyle", required = true)
    @ApiResponse(code = 201, message = "创建成功")
    public ResponseEntity addPlan(@RequestBody CustomStyle customStyle) {
        return ResponseEntity.ok(customStyleService.addCustomStyle(customStyle));
    }

    @DeleteMapping("/{customStyleId}")
    @ApiOperation(notes = "删除格式化方案", value = "删除格式化方案")
    @ApiImplicitParam(paramType = "path", dataType = "int", name = "customStyleId", required = true)
    @ApiResponses(@ApiResponse(code = 200, message = "ok", response = Integer.class))
    public ResponseEntity deleteLink(@PathVariable Integer customStyleId) {
        return ResponseEntity.ok(customStyleService.deleteCustomStyle(customStyleId));
    }

    @PutMapping("/{customStyleId}")
    @ApiOperation(notes = "编辑格式化方案", value = "编辑格式化方案")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "customStyleId", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "CustomStyle", name = "customStyle", required = true)
    })
    @ApiResponses(@ApiResponse(code = 200, message = "ok", response = CustomStyle.class))
    public ResponseEntity editLink(@PathVariable Integer customStyleId, @RequestBody CustomStyle customStyle) {
        customStyle.setId(customStyleId);
        customStyleService.updateCustomStyle(customStyle);
        return ResponseEntity.ok(customStyle);
    }
    @GetMapping("/{customStyleId}")
    @ApiOperation(notes = "获取格式化方案", value = "获取格式化方案")
    @ApiImplicitParam(paramType = "path", dataType = "int", name = "customStyleId", required = true)
    @ApiResponses(@ApiResponse(code = 200, message = "ok", response = CustomStyle.class))
    public ResponseEntity getCustomStyle(@PathVariable Integer customStyleId) {
        return ResponseEntity.ok(customStyleService.select(customStyleId));
    }

    @GetMapping("/all")
    @ApiOperation(notes = "获取所有格式化方案", value = "获取所有格式化方案")
    @ApiResponses(@ApiResponse(code = 200, message = "ok", response = CustomStyle.class))
    public ResponseEntity getAllCustomStyle() {
        return ResponseEntity.ok(customStyleService.listCustomStyle());
    }


}
